#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <chrono>

void bubbleSort(std::vector<std::string>& nums) {
    bool swapped = true;
    while (swapped) {
        swapped = false;
        for (size_t i = 0; i < nums.size() - 1; ++i) {
            if (nums[i] > nums[i + 1]) {
                std::swap(nums[i], nums[i + 1]);
                swapped = true;
            }
        }
    }
}

std::vector<std::string> read2list(const std::string& filename) {
    std::ifstream file(filename);
    std::vector<std::string> data;
    std::string line;
    while (std::getline(file, line)) {
        data.push_back(line);
    }
    return data;
}

int main() {
    std::vector<std::string> m1 = read2list("m1_sorted.txt");
    std::vector<std::string> m2 = read2list("m2_reverse.txt");
    std::vector<std::string> m3 = read2list("m3_shuffle.txt");

    auto t_start = std::chrono::high_resolution_clock::now();
    bubbleSort(m1);
    auto t_finish = std::chrono::high_resolution_clock::now();
    std::cout << "m1_sorted " << std::chrono::duration_cast<std::chrono::milliseconds>(t_finish - t_start).count() << " milliseconds" << std::endl;

    t_start = std::chrono::high_resolution_clock::now();
    bubbleSort(m2);
    t_finish = std::chrono::high_resolution_clock::now();
    std::cout << "m2_reverse " << std::chrono::duration_cast<std::chrono::milliseconds>(t_finish - t_start).count() << " milliseconds" << std::endl;

    t_start = std::chrono::high_resolution_clock::now();
    bubbleSort(m3);
    t_finish = std::chrono::high_resolution_clock::now();
    std::cout << "m3_shuffle " << std::chrono::duration_cast<std::chrono::milliseconds>(t_finish - t_start).count() << " milliseconds" << std::endl;

    return 0;
}
